package com.database;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Login extends JFrame implements ActionListener{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel driver_jl;
	private JLabel url_jl;
	private JLabel username_jl;
	private JLabel password_jl;
	private JTextField driver_jt;
	private JTextField url_jt;
	private JTextField username_jt;
	private JPasswordField password_jt;
	private JButton login;
	private JButton exit;
	public Login() {
		this.setTitle("a");
		this.setBounds(500, 300, 300, 300);
		this.setLayout(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setAlwaysOnTop(true);
		this.setResizable(false);
		init();
	}
	private void init(){
		driver_jl = new JLabel("driver");
		driver_jl.setBounds(20, 20, 60, 30);
		this.add(driver_jl);
		url_jl = new JLabel("url");
		url_jl.setBounds(20, 70, 60, 30);
		this.add(url_jl);
		username_jl = new JLabel("username");
		username_jl.setBounds(20, 120, 60, 30);
		this.add(username_jl);
		password_jl = new JLabel("password");
		password_jl.setBounds(20, 170, 60, 30);
		this.add(password_jl);
		driver_jt = new JTextField();
		driver_jt.setBounds(100, 20, 160, 30);
		this.add(driver_jt);
		url_jt = new JTextField();
		url_jt.setBounds(100, 70, 160, 30);
		this.add(url_jt);
		username_jt = new JTextField();
		username_jt.setBounds(100, 120, 160, 30);
		this.add(username_jt);
		password_jt = new JPasswordField();
		password_jt.setBounds(100, 170, 160, 30);
		this.add(password_jt);
		login = new JButton("login");
		login.setBounds(50, 220, 80, 30);
		this.add(login);
		login.addActionListener(this);
		exit = new JButton("exit");
		exit.setBounds(160, 220, 80, 30);
		this.add(exit);
		exit.addActionListener(this);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==login){
			int res = DBUtil.getConnection();
			List<String> tables = DBUtil.getTables();
			System.out.println(res);
			this.dispose();
			DBFrame dbf = new DBFrame(tables);
			dbf.setVisible(true);
		}else if(e.getSource()==exit){
			
		}
	}
	public static void main(String[] args) {
		Login login = new Login();
		login.setVisible(true);
	}
}
